package io.renren.modules.file.service.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.file.dao.ServerNodeDao;
import io.renren.modules.file.entity.ServerNodeEntity;
import io.renren.modules.file.service.ServerNodeService;


@Service("serverNodeService")
public class ServerNodeServiceImpl extends ServiceImpl<ServerNodeDao, ServerNodeEntity> implements ServerNodeService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String name = ((String)params.get("name"));
        if (StringUtils.isNotBlank(name)) {
            name = name.trim();
        }
        IPage<ServerNodeEntity> page = this.page(
                new Query<ServerNodeEntity>().getPage(params),
                new QueryWrapper<ServerNodeEntity>().like(StringUtils.isNotBlank(name),"name", name).or()
                        .like(StringUtils.isNotBlank(name),"ip", name).or()
                        .like(StringUtils.isNotBlank(name),"port", name).or()
                        .like(StringUtils.isNotBlank(name),"user", name)
        );
        return new PageUtils(page);
    }
}
